package noip.toonsnet.app.preference;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class CalendarListPreference extends Preference {
	public static int maximum    = 100;
	public static int interval   = 5;
 
	private float oldValue = 50;
	private TextView monitorBox;
 
 
	public CalendarListPreference(Context context) {
		super(context);
	}
 
	public CalendarListPreference(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
 
	public CalendarListPreference(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}
   
	@Override
	protected View onCreateView(ViewGroup parent){
		LinearLayout layout = new LinearLayout(getContext());
   
		LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
		params1.gravity = Gravity.LEFT;
		params1.weight  = 1.0f;
   
		LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(80, LinearLayout.LayoutParams.WRAP_CONTENT);
		params2.gravity = Gravity.RIGHT;
   
		LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(30, LinearLayout.LayoutParams.WRAP_CONTENT);
		params3.gravity = Gravity.CENTER;
   
		layout.setPadding(15, 5, 10, 5);
		layout.setOrientation(LinearLayout.HORIZONTAL);
   
		TextView view = new TextView(getContext());
		view.setText(getTitle());
		view.setTextSize(18);
		view.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
		view.setGravity(Gravity.LEFT);
		view.setLayoutParams(params1);
   
		SeekBar bar = new SeekBar(getContext());
		bar.setMax(maximum);
		bar.setProgress((int)this.oldValue);
		bar.setLayoutParams(params2);
//		bar.setOnSeekBarChangeListener(this);
		
//		final CharSequence[] items = {"Red", "Green", "Blue"};
//		
//		AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
//		builder.setTitle("Pick a color");
//		builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
//		    public void onClick(DialogInterface dialog, int item) {
//		        Toast.makeText(getContext(), items[item], Toast.LENGTH_SHORT).show();
//		    }
//		});
//		AlertDialog alert = builder.create();
		
   
		this.monitorBox = new TextView(getContext());
		this.monitorBox.setTextSize(12);
		this.monitorBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
		this.monitorBox.setLayoutParams(params3);
		this.monitorBox.setPadding(2, 5, 0, 0);
		this.monitorBox.setText(bar.getProgress()+"");
   
		layout.addView(view);
		layout.addView(bar);
		layout.addView(this.monitorBox);
		layout.setId(android.R.id.widget_frame);
   
		return layout; 
	}
}
